/**
 *
 * @author Robbert
 */
package three2learn.Controller;

import java.io.*;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;
import org.hibernate.Session;
import org.hibernate.Transaction;
import three2learn.Model.Course;
import three2learn.service.HibernateUtil;

public class CourseController extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {

        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        Transaction trans = session.beginTransaction();
        List<Course> courseLijst = session.createQuery("from Course").list();

        request.setAttribute("aantalCourses", courseLijst.size());
        request.setAttribute("coursesUitSessie", courseLijst);

        String address = "/courseOverview.jsp";
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);
        dispatcher.forward(request, response);
    }
}
